﻿Public Class SnakeBody
    '######################## 静态属性
    '头结点
    Public head As SnakeNode
    '速度
    Dim velocity As Int32
    '方向
    Dim direction As Int32
    '得分
    Dim score As Int32
    '长度
    Dim length As Int32

    '######################## 动态属性
    '构造方法
    Sub New()
        '初始化的蛇长度为3
        Dim p1 As SnakeNode
        Dim p2 As SnakeNode
        head = New SnakeNode(15, 6)
        p1 = New SnakeNode(14, 6)
        p2 = New SnakeNode(13, 6)
        head.preNode = p2
        p2.nextNode = head
        p2.preNode = p1
        p1.nextNode = p2
        head.nextNode = p1
        p1.preNode = head
        length = 3
        score = 0
    End Sub
    '获取速度
    Function getVelocity() As Int32
        Return velocity
    End Function
    '设置速度
    Sub setVelocity(v As Int32)
        velocity = v
    End Sub
    '获取方向{1:上，2:左，3:下，4:右}
    Function getDirection() As Int32
        Return direction
    End Function
    '设置方向
    Sub setDirection(d As Int32)
        direction = d
    End Sub
    '获取分数
    Function getScore() As Int32
        Return score
    End Function
    '增加分数
    Sub addScore(add As Int32, rand As Int32)
        Dim R As New Random()
        '随机修正项
        Dim s As Int32 = R.Next(rand + 1)
        '正负号
        Dim pm As Int32 = R.Next(2)
        Debug.Print(pm)
        If (pm = 0) Then
            score += (add + s)
        Else
            score += (add - s)
        End If
    End Sub
    '获取长度
    Function getLength() As Int32
        Return length
    End Function
    '增加长度
    Sub addLength()
        length += 1
    End Sub
End Class
